home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1999 November / SOTMC_Nov1999-Ultimate.iso / mac / REALbasic ƒ / Examples / Techniques / Examples by Thomas Tempelmann / FAQs from RB-NUG mailing list / Exception Handling / Exception Handling.rsrc
MacOS Resource Fork  |  1999-07-06  |  11.4 KB  |  [clpt/drag]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: MacOS Resource Fork (archive/rsrc).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert MacOS Resource Fork (archive/rsrc) magic Supported
10% dexvert Jesper Olsen Module (music/jesperOlsen) magic Supported
1% dexvert BeOS Resource Data (archive/beOSResourceData) ext Unsupported
1% dexvert AppleSingle (archive/appleSingle) fallback Supported
100% file AppleDouble encoded Macintosh file default
99% file data default
56% TrID Mac AppleDouble encoded default
28% TrID TTComp archive compressed (bin-2K) default (weak)
14% TrID MacBinary 1 default (weak)
1% dearkID deark: applesd (AppleDouble header file) default (weak)
100% lsar AppleSingle default
100% gt2 MAC Bilddatei default (weak)


id metadata
keyvalue
macFileType[clpt]
macFileCreator[drag]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 05 16 07 00 02 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000010| 00 00 00 00 00 00 00 00 | 00 02 00 00 00 09 00 00 |........|........|
|00000020| 00 32 00 00 00 20 00 00 | 00 02 00 00 00 52 00 00 |.2... ..|.....R..|
|00000030| 2d 20 63 6c 70 74 64 72 | 61 67 01 00 00 00 00 00 |- clptdr|ag......|
|00000040| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000050| 00 00 00 00 01 00 00 00 | 2c b2 00 00 2b b2 00 00 |........|,...+...|
|00000060| 00 6e 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |.n......|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000080| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000090| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000a0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000b0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000c0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000100| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000110| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000120| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000130| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000140| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000150| 00 00 00 00 2b 38 4a 75 | 73 74 20 74 68 69 73 20 |....+8Ju|st this |
|00000160| 6d 6f 72 6e 69 6e 67 20 | 28 61 63 74 75 61 6c 6c |morning |(actuall|
|00000170| 79 2c 20 73 74 69 6c 6c | 20 6c 61 79 69 6e 67 20 |y, still| laying |
|00000180| 69 6e 20 62 65 64 20 69 | 6e 20 74 68 61 74 20 6b |in bed i|n that k|
|00000190| 69 6e 64 0d 6f 66 20 6e | 6f 74 2d 64 72 65 61 6d |ind.of n|ot-dream|
|000001a0| 69 6e 67 2d 61 6e 79 6d | 6f 72 65 20 6d 6f 64 65 |ing-anym|ore mode|
|000001b0| 29 2c 20 69 74 20 61 70 | 70 65 61 72 65 64 20 74 |), it ap|peared t|
|000001c0| 6f 20 6d 65 20 68 6f 77 | 20 65 61 73 79 20 61 6e |o me how| easy an|
|000001d0| 64 0d 6e 69 63 65 6c 79 | 20 79 6f 75 20 63 61 6e |d.nicely| you can|
|000001e0| 20 64 6f 20 65 78 63 65 | 70 74 69 6f 6e 20 68 61 | do exce|ption ha|
|000001f0| 6e 64 6c 69 6e 67 20 77 | 69 74 68 20 52 42 20 28 |ndling w|ith RB (|
|00000200| 49 20 6b 6e 65 77 20 61 | 6c 72 65 61 64 79 0d 69 |I knew a|lready.i|
|00000210| 74 73 20 62 61 73 69 63 | 73 2c 20 62 75 74 20 74 |ts basic|s, but t|
|00000220| 68 65 20 72 65 61 6c 69 | 7a 61 74 69 6f 6e 20 74 |he reali|zation t|
|00000230| 68 61 74 20 61 6e 20 45 | 78 63 65 70 74 69 6f 6e |hat an E|xception|
|00000240| 20 63 61 6e 20 62 65 0d | 65 78 74 65 6e 64 65 64 | can be.|extended|
|00000250| 20 62 65 63 61 75 73 65 | 20 6f 66 20 69 74 73 20 | because| of its |
|00000260| 6e 61 74 75 72 65 20 6f | 66 20 62 65 69 6e 67 20 |nature o|f being |
|00000270| 61 20 63 6c 61 73 73 2c | 20 73 74 72 75 63 6b 0d |a class,| struck.|
|00000280| 6d 65 20 6c 69 6b 65 20 | 6c 69 67 68 74 6e 69 6e |me like |lightnin|
|00000290| 67 20 61 6e 64 20 6d 61 | 64 65 20 6d 65 20 6a 75 |g and ma|de me ju|
|000002a0| 6d 70 20 6f 75 74 20 6f | 66 20 74 68 65 20 62 65 |mp out o|f the be|
|000002b0| 64 20 72 69 67 68 74 0d | 61 77 61 79 20 61 6e 64 |d right.|away and|
|000002c0| 20 74 75 72 6e 69 6e 67 | 20 6d 65 20 4d 61 63 20 | turning| me Mac |
|000002d0| 6f 6e 20 74 6f 20 77 72 | 69 74 65 20 74 68 69 73 |on to wr|ite this|
|000002e0| 20 64 6f 77 6e 20 66 6f | 72 20 61 6c 6c 20 6f 66 | down fo|r all of|
|000002f0| 20 79 6f 75 29 3a 0d 0d | 45 78 63 65 70 74 69 6f | you):..|Exceptio|
|00000300| 6e 20 28 6f 72 20 65 72 | 72 6f 72 29 20 68 61 6e |n (or er|ror) han|
|00000310| 64 6c 69 6e 67 20 69 73 | 20 68 61 72 64 6c 79 20 |dling is| hardly |
|00000320| 64 6f 63 75 6d 65 6e 74 | 65 64 20 69 6e 20 52 42 |document|ed in RB|
|00000330| 3b 0d 74 68 65 79 20 6f | 6e 6c 79 20 67 69 76 65 |;.they o|nly give|
|00000340| 20 79 6f 75 20 73 6f 6d | 65 20 73 68 6f 72 74 20 | you som|e short |
|00000350| 65 78 70 6c 61 6e 61 74 | 69 6f 6e 20 6f 66 20 69 |explanat|ion of i|
|00000360| 74 73 20 73 79 6e 74 61 | 78 2c 0d 62 75 74 20 6e |ts synta|x,.but n|
|00000370| 6f 20 72 65 61 6c 2d 77 | 6f 72 6c 64 20 65 78 61 |o real-w|orld exa|
|00000380| 6d 70 6c 65 73 20 6f 72 | 20 6f 74 68 65 72 20 69 |mples or| other i|
|00000390| 64 65 61 73 20 66 6f 72 | 20 77 68 61 74 20 69 74 |deas for| what it|
|000003a0| 20 69 73 0d 67 6f 6f 64 | 20 66 6f 72 2e 0d 0d 4f | is.good| for...O|
|000003b0| 4b 2c 20 73 6f 20 6c 65 | 74 27 73 20 6d 61 6b 65 |K, so le|t's make|
|000003c0| 20 74 68 69 73 20 6f 6e | 65 20 61 20 6c 69 74 74 | this on|e a litt|
|000003d0| 6c 65 20 74 75 74 6f 72 | 69 61 6c 20 66 6f 72 20 |le tutor|ial for |
|000003e0| 61 6c 6c 20 6f 66 0d 79 | 6f 75 20 52 42 20 75 73 |all of.y|ou RB us|
|000003f0| 65 72 73 20 74 68 61 74 | 20 61 72 65 20 6b 69 6e |ers that| are kin|
|00000400| 64 20 6f 66 20 6e 65 77 | 20 74 6f 20 4f 62 6a 65 |d of new| to Obje|
|00000410| 63 74 20 6f 72 69 65 6e | 74 65 64 20 61 6e 64 0d |ct orien|ted and.|
|00000420| 6f 74 68 65 72 20 6d 6f | 64 65 72 6e 20 70 72 6f |other mo|dern pro|
|00000430| 67 72 61 6d 6d 69 6e 67 | 20 74 65 63 68 6e 69 71 |gramming| techniq|
|00000440| 75 65 73 2e 0d 0d 42 54 | 57 2c 20 68 65 72 65 27 |ues...BT|W, here'|
|00000450| 73 20 6d 79 20 6c 69 74 | 74 6c 65 20 63 6f 70 79 |s my lit|tle copy|
|00000460| 72 69 67 68 74 20 6e 6f | 74 69 63 65 3a 20 72 65 |right no|tice: re|
|00000470| 64 69 73 74 72 69 62 75 | 74 69 6f 6e 0d 6f 66 20 |distribu|tion.of |
|00000480| 74 68 69 73 20 69 73 20 | 70 65 72 6d 69 74 74 65 |this is |permitte|
|00000490| 64 20 61 73 20 6c 6f 6e | 67 20 61 73 20 69 74 20 |d as lon|g as it |
|000004a0| 69 73 20 64 6f 6e 65 20 | 66 6f 72 20 66 72 65 65 |is done |for free|
|000004b0| 2e 20 49 0d 72 65 74 61 | 69 6e 20 74 68 65 20 63 |. I.reta|in the c|
|000004c0| 6f 70 79 72 69 67 68 74 | 2e 20 54 68 6f 6d 61 73 |opyright|. Thomas|
|000004d0| 20 54 65 6d 70 65 6c 6d | 61 6e 6e 20 28 72 62 40 | Tempelm|ann (rb@|
|000004e0| 74 65 6d 70 65 6c 2e 6f | 72 67 29 2e 0d 0d 0d 57 |tempel.o|rg)....W|
|000004f0| 68 61 74 27 73 20 74 68 | 65 20 70 75 72 70 6f 73 |hat's th|e purpos|
|00000500| 65 20 6f 66 20 45 78 63 | 65 70 74 69 6f 6e 20 48 |e of Exc|eption H|
|00000510| 61 6e 64 6c 69 6e 67 3f | 0d 2d 2d 2d 2d 2d 2d 2d |andling?|.-------|
|00000520| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000530| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000540| 2d 2d 0d 0d 45 78 63 65 | 70 74 69 6f 6e 20 68 61 |--..Exce|ption ha|
|00000550| 6e 64 6c 69 6e 67 20 63 | 6f 6d 65 73 20 69 6e 20 |ndling c|omes in |
|00000560| 68 61 6e 64 79 20 67 65 | 6e 65 72 61 6c 6c 79 20 |handy ge|nerally |
|00000570| 61 6e 79 0d 74 69 6d 65 | 20 79 6f 75 20 77 61 6e |any.time| you wan|
|00000580| 74 20 74 6f 20 61 62 6f | 72 74 20 61 20 70 72 6f |t to abo|rt a pro|
|00000590| 63 65 73 73 20 69 6e 20 | 61 20 70 72 6f 63 65 64 |cess in |a proced|
|000005a0| 75 72 65 0d 28 73 75 62 | 72 6f 75 74 69 6e 65 29 |ure.(sub|routine)|
|000005b0| 20 62 65 63 61 75 73 65 | 20 6f 66 20 73 6f 6d 65 | because| of some|
|000005c0| 20 65 72 72 6f 72 20 63 | 6f 6e 64 69 74 69 6f 6e | error c|ondition|
|000005d0| 2e 0d 0d 43 6f 6e 73 69 | 64 65 72 20 79 6f 75 20 |...Consi|der you |
|000005e0| 77 72 69 74 65 20 61 20 | 70 72 6f 63 65 64 75 72 |write a |procedur|
|000005f0| 65 20 74 68 61 74 20 61 | 64 64 73 20 61 20 6c 69 |e that a|dds a li|
|00000600| 6e 65 0d 6f 66 20 74 65 | 78 74 20 70 6c 75 73 20 |ne.of te|xt plus |
|00000610| 61 20 6e 75 6d 62 65 72 | 2c 20 74 68 61 74 20 61 |a number|, that a|
|00000620| 6c 77 61 79 73 20 69 73 | 20 73 75 70 70 6f 73 65 |lways is| suppose|
|00000630| 64 0d 74 6f 20 62 65 20 | 70 6f 73 69 74 69 76 65 |d.to be |positive|
|00000640| 2c 20 74 6f 20 61 20 66 | 69 6c 65 2e 20 54 68 65 |, to a f|ile. The|
|00000650| 20 62 61 73 69 63 20 63 | 6f 64 65 20 77 6f 75 6c | basic c|ode woul|
|00000660| 64 0d 6c 6f 6f 6b 20 6c | 69 6b 65 20 74 68 69 73 |d.look l|ike this|
|00000670| 3a 0d 0d 20 20 53 75 62 | 20 41 64 64 4c 69 6e 65 |:.. Sub| AddLine|
|00000680| 54 6f 54 65 78 74 66 69 | 6c 65 28 74 65 78 74 20 |ToTextfi|le(text |
|00000690| 61 73 20 53 74 72 69 6e | 67 2c 20 70 6f 73 4e 75 |as Strin|g, posNu|
|000006a0| 6d 20 61 73 20 49 6e 74 | 65 67 65 72 2c 20 66 69 |m as Int|eger, fi|
|000006b0| 6c 65 52 65 66 20 61 73 | 20 46 6f 6c 64 65 72 49 |leRef as| FolderI|
|000006c0| 74 65 6d 29 0d 20 20 20 | 20 44 69 6d 20 66 69 6c |tem). | Dim fil|
|000006d0| 65 53 74 72 65 61 6d 20 | 41 73 20 54 65 78 74 4f |eStream |As TextO|
|000006e0| 75 74 70 75 74 53 74 72 | 65 61 6d 0d 20 20 20 20 |utputStr|eam. |
|000006f0| 0d 20 20 20 20 66 69 6c | 65 53 74 72 65 61 6d 20 |. fil|eStream |
|00000700| 3d 20 66 69 6c 65 52 65 | 66 2e 41 70 70 65 6e 64 |= fileRe|f.Append|
|00000710| 54 6f 54 65 78 74 46 69 | 6c 65 0d 20 20 20 20 66 |ToTextFi|le. f|
|00000720| 69 6c 65 53 74 72 65 61 | 6d 2e 57 72 69 74 65 4c |ileStrea|m.WriteL|
|00000730| 69 6e 65 20 28 74 65 78 | 74 20 2b 20 22 20 28 74 |ine (tex|t + " (t|
|00000740| 68 65 20 6e 75 6d 62 65 | 72 20 69 73 3a 20 22 20 |he numbe|r is: " |
|00000750| 2b 20 53 74 72 28 70 6f | 73 4e 75 6d 29 20 2b 20 |+ Str(po|sNum) + |
|00000760| 22 29 22 29 0d 20 20 20 | 20 66 69 6c 65 53 74 72 |")"). | fileStr|
|00000770| 65 61 6d 2e 43 6c 6f 73 | 65 0d 20 20 45 6e 64 20 |eam.Clos|e. End |
|00000780| 53 75 62 0d 0d 54 68 65 | 20 63 6f 64 65 20 75 73 |Sub..The| code us|
|00000790| 69 6e 67 20 74 68 61 74 | 20 73 75 62 72 6f 75 74 |ing that| subrout|
|000007a0| 69 6e 65 20 63 6f 75 6c | 64 20 62 65 20 6c 69 6b |ine coul|d be lik|
|000007b0| 65 20 74 68 69 73 3a 0d | 0d 20 20 53 75 62 20 57 |e this:.|. Sub W|
|000007c0| 72 69 74 65 53 6f 6d 65 | 4c 69 6e 65 73 54 6f 41 |riteSome|LinesToA|
|000007d0| 46 69 6c 65 28 29 0d 20 | 20 20 20 44 69 6d 20 74 |File(). | Dim t|
|000007e0| 6d 70 46 69 6c 65 52 65 | 66 20 61 73 20 46 6f 6c |mpFileRe|f as Fol|
|000007f0| 64 65 72 49 74 65 6d 0d | 20 20 20 20 74 6d 70 46 |derItem.| tmpF|
|00000800| 69 6c 65 52 65 66 20 3d | 20 47 65 74 46 6f 6c 64 |ileRef =| GetFold|
|00000810| 65 72 49 74 65 6d 28 22 | 74 6d 70 46 69 6c 65 2e |erItem("|tmpFile.|
|00000820| 74 78 74 22 29 0d 20 20 | 20 20 0d 20 20 20 20 69 |txt"). | . i|
|00000830| 66 20 74 6d 70 46 69 6c | 65 52 65 66 2e 45 78 69 |f tmpFil|eRef.Exi|
|00000840| 73 74 73 20 74 68 65 6e | 0d 20 20 20 20 20 20 74 |sts then|. t|
|00000850| 6d 70 46 69 6c 65 52 65 | 66 2e 44 65 6c 65 74 65 |mpFileRe|f.Delete|
|00000860| 28 29 0d 20 20 20 20 65 | 6e 64 0d 20 20 20 20 0d |(). e|nd. .|
|00000870| 20 20 20 20 41 64 64 4c | 69 6e 65 54 6f 54 65 78 | AddL|ineToTex|
|00000880| 74 66 69 6c 65 28 22 32 | 2a 32 22 2c 20 32 2a 32 |tfile("2|*2", 2*2|
|00000890| 2c 20 74 6d 70 46 69 6c | 65 52 65 66 29 0d 20 20 |, tmpFil|eRef). |
|000008a0| 20 20 41 64 64 4c 69 6e | 65 54 6f 54 65 78 74 66 | AddLin|eToTextf|
|000008b0| 69 6c 65 28 22 35 2a 35 | 22 2c 20 35 2a 35 2c 20 |ile("5*5|", 5*5, |
|000008c0| 74 6d 70 46 69 6c 65 52 | 65 66 29 0d 20 20 45 6e |tmpFileR|ef). En|
|000008d0| 64 20 53 75 62 0d 0d 54 | 68 65 20 70 72 6f 62 6c |d Sub..T|he probl|
|000008e0| 65 6d 20 69 73 20 74 68 | 61 74 20 74 68 65 20 41 |em is th|at the A|
|000008f0| 64 64 4c 69 6e 65 54 6f | 54 65 78 74 66 69 6c 65 |ddLineTo|Textfile|
|00000900| 20 72 6f 75 74 69 6e 65 | 20 63 61 6e 0d 6e 6f 74 | routine| can.not|
|00000910| 20 61 6c 77 61 79 73 20 | 62 65 20 73 75 72 65 20 | always |be sure |
|00000920| 74 68 61 74 20 69 74 73 | 20 63 61 6c 6c 65 72 20 |that its| caller |
|00000930| 68 61 73 20 73 65 74 20 | 75 70 20 65 76 65 72 79 |has set |up every|
|00000940| 74 68 69 6e 67 0d 63 6f | 72 72 65 63 74 6c 79 3a |thing.co|rrectly:|
|00000950| 0d 0d 54 68 65 72 65 27 | 73 20 73 65 76 65 72 61 |..There'|s severa|
|00000960| 6c 20 63 6f 6e 64 69 74 | 69 6f 6e 73 20 74 68 61 |l condit|ions tha|
|00000970| 74 20 74 68 65 20 63 61 | 6c 6c 65 72 20 6d 75 73 |t the ca|ller mus|
|00000980| 74 20 6d 65 65 74 3a 0d | 2a 20 54 68 65 20 66 69 |t meet:.|* The fi|
|00000990| 6c 65 52 65 66 20 6d 75 | 73 74 20 69 64 65 6e 74 |leRef mu|st ident|
|000009a0| 69 66 79 20 61 20 66 69 | 6c 65 20 28 61 6e 64 20 |ify a fi|le (and |
|000009b0| 6e 6f 74 20 61 20 66 6f | 6c 64 65 72 0d 20 20 6f |not a fo|lder. o|
|000009c0| 72 20 73 6f 6d 65 20 6f | 74 68 65 72 20 69 6e 76 |r some o|ther inv|
|000009d0| 61 6c 69 64 20 6f 62 6a | 65 63 74 29 2c 0d 2a 20 |alid obj|ect),.* |
|000009e0| 74 68 65 20 66 69 6c 65 | 20 6d 75 73 74 20 62 65 |the file| must be|
|000009f0| 20 77 72 69 74 61 62 6c | 65 20 28 6e 6f 74 20 6c | writabl|e (not l|
|00000a00| 6f 63 6b 65 64 29 20 61 | 6e 64 0d 2a 20 74 68 65 |ocked) a|nd.* the|
|00000a10| 20 6e 75 6d 62 65 72 20 | 6d 75 73 74 20 62 65 20 | number |must be |
|00000a20| 70 6f 73 69 74 69 76 65 | 2e 0d 0d 41 73 20 6c 6f |positive|...As lo|
|00000a30| 6e 67 20 61 73 20 79 6f | 75 20 6b 6e 6f 77 20 74 |ng as yo|u know t|
|00000a40| 68 65 73 65 20 63 6f 6e | 64 69 74 69 6f 6e 73 2c |hese con|ditions,|
|00000a50| 20 79 6f 75 20 63 61 6e | 0d 6d 61 6b 65 20 73 75 | you can|.make su|
|00000a60| 72 65 20 74 68 61 74 20 | 79 6f 75 20 6d 65 65 74 |re that |you meet|
|00000a70| 20 74 68 65 6d 20 62 65 | 66 6f 72 65 20 79 6f 75 | them be|fore you|
|00000a80| 20 63 61 6c 6c 20 74 68 | 65 0d 73 75 62 72 6f 75 | call th|e.subrou|
|00000a90| 74 69 6e 65 2e 0d 0d 46 | 6f 72 20 69 6e 73 74 61 |tine...F|or insta|
|00000aa0| 6e 63 65 2c 20 69 66 20 | 79 6f 75 20 6c 61 74 65 |nce, if |you late|
|00000ab0| 72 20 77 61 6e 74 20 74 | 6f 20 72 65 2d 75 73 65 |r want t|o re-use|
|00000ac0| 20 74 68 65 0d 41 64 64 | 4c 69 6e 65 54 6f 54 65 | the.Add|LineToTe|
|00000ad0| 78 74 66 69 6c 65 20 72 | 6f 75 74 69 6e 65 20 69 |xtfile r|outine i|
|00000ae0| 6e 20 6f 74 68 65 72 20 | 70 72 6f 6a 65 63 74 73 |n other |projects|
|00000af0| 2c 20 6f 72 20 65 76 65 | 6e 0d 70 75 62 6c 69 73 |, or eve|n.publis|
|00000b00| 68 20 69 74 20 74 6f 20 | 74 68 65 20 70 75 62 6c |h it to |the publ|
|00000b10| 69 63 2c 20 79 6f 75 20 | 77 61 6e 74 20 74 6f 20 |ic, you |want to |
|00000b20| 6d 61 6b 65 20 73 75 72 | 65 20 69 6e 0d 61 64 76 |make sur|e in.adv|
|00000b30| 61 6e 63 65 20 74 68 61 | 74 20 79 6f 75 72 20 73 |ance tha|t your s|
|00000b40| 75 62 72 6f 75 74 69 6e | 65 20 69 73 20 63 61 6c |ubroutin|e is cal|
|00000b50| 6c 65 64 20 70 72 6f 70 | 65 72 6c 79 2e 0d 0d 48 |led prop|erly...H|
|00000b60| 6f 77 20 63 61 6e 20 79 | 6f 75 20 6d 61 6b 65 20 |ow can y|ou make |
|00000b70| 73 75 72 65 20 74 68 61 | 74 20 74 68 65 73 65 20 |sure tha|t these |
|00000b80| 63 6f 6e 64 69 74 69 6f | 6e 73 20 61 72 65 0d 6d |conditio|ns are.m|
|00000b90| 65 74 3f 0d 2a 20 45 69 | 74 68 65 72 20 79 6f 75 |et?.* Ei|ther you|
|00000ba0| 20 64 6f 63 75 6d 65 6e | 74 20 74 68 65 20 63 6f | documen|t the co|
|00000bb0| 6e 64 69 74 69 6f 6e 73 | 20 61 6e 64 20 68 6f 70 |nditions| and hop|
|00000bc0| 65 20 74 68 61 74 0d 20 | 20 74 68 65 20 70 72 6f |e that. | the pro|
|00000bd0| 67 72 61 6d 6d 65 72 20 | 75 73 69 6e 67 20 74 68 |grammer |using th|
|00000be0| 69 73 20 73 75 62 72 6f | 75 74 69 6e 65 20 77 69 |is subro|utine wi|
|00000bf0| 6c 6c 20 72 65 61 64 20 | 61 6e 64 0d 20 20 66 6f |ll read |and. fo|
|00000c00| 6c 6c 6f 77 20 74 68 65 | 6d 20 28 6f 74 68 65 72 |llow the|m (other|
|00000c10| 77 69 73 65 20 68 65 27 | 6c 6c 20 68 61 76 65 20 |wise he'|ll have |
|00000c20| 74 6f 20 64 65 62 75 67 | 20 68 69 73 20 63 6f 64 |to debug| his cod|
|00000c30| 65 29 2c 0d 2a 20 6f 72 | 20 79 6f 75 20 70 72 6f |e),.* or| you pro|
|00000c40| 76 69 64 65 20 6d 6f 73 | 74 20 6f 66 20 74 68 65 |vide mos|t of the|
|00000c50| 20 68 65 6c 70 20 62 79 | 20 75 73 69 6e 67 20 74 | help by| using t|
|00000c60| 68 65 20 65 78 65 63 70 | 74 69 6f 6e 0d 20 20 68 |he execp|tion. h|
|00000c70| 61 6e 64 6c 69 6e 67 2e | 0d 0d 0d 52 61 69 73 69 |andling.|...Raisi|
|00000c80| 6e 67 20 45 78 63 65 70 | 74 69 6f 6e 73 0d 2d 2d |ng Excep|tions.--|
|00000c90| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000ca0| 0d 0d 57 68 65 6e 20 79 | 6f 75 20 64 65 74 65 63 |..When y|ou detec|
|00000cb0| 74 20 61 6e 20 65 72 72 | 6f 72 20 63 6f 6e 64 69 |t an err|or condi|
|00000cc0| 74 69 6f 6e 20 69 6e 20 | 79 6f 75 72 20 73 75 62 |tion in |your sub|
|00000cd0| 72 6f 75 74 69 6e 65 2c | 0d 61 6e 64 20 79 6f 75 |routine,|.and you|
|00000ce0| 20 77 61 6e 74 20 74 6f | 20 68 61 6e 64 6c 65 20 | want to| handle |
|00000cf0| 69 74 2c 20 74 68 65 20 | 63 6c 61 73 73 69 63 20 |it, the |classic |
|00000d00| 77 61 79 20 77 6f 75 6c | 64 20 6c 6f 6f 6b 0d 6c |way woul|d look.l|
|00000d10| 69 6b 65 20 74 68 69 73 | 3a 0d 0d 20 20 2f 2f 20 |ike this|:.. // |
|00000d20| 6d 61 6b 65 20 73 75 72 | 65 20 74 68 61 74 20 74 |make sur|e that t|
|00000d30| 68 65 20 70 61 73 73 65 | 64 20 6e 75 6d 62 65 72 |he passe|d number|
|00000d40| 20 69 73 20 70 6f 73 69 | 74 69 76 65 3a 0d 20 20 | is posi|tive:. |
|00000d50| 49 46 20 70 6f 73 4e 75 | 6d 20 3c 20 30 20 54 48 |IF posNu|m < 0 TH|
|00000d60| 45 4e 0d 20 20 20 20 2f | 2f 20 6f 6f 70 73 20 2d |EN. /|/ oops -|
|00000d70| 20 65 72 72 6f 72 21 0d | 20 20 20 20 52 45 54 55 | error!.| RETU|
|00000d80| 52 4e 0d 20 20 45 4e 44 | 0d 20 20 49 46 20 66 69 |RN. END|. IF fi|
|00000d90| 6c 65 52 65 66 20 3d 20 | 4e 49 4c 20 54 48 45 4e |leRef = |NIL THEN|
|00000da0| 0d 20 20 20 20 2f 2f 20 | 6f 6f 70 73 20 2d 20 61 |. // |oops - a|
|00000db0| 6e 6f 74 68 65 72 20 65 | 72 72 6f 72 21 0d 20 20 |nother e|rror!. |
|00000dc0| 20 20 52 45 54 55 52 4e | 0d 20 20 45 4e 44 0d 20 | RETURN|. END. |
|00000dd0| 20 2f 2f 20 2e 2e 2e 20 | 67 6f 20 6f 6e 20 77 69 | // ... |go on wi|
|00000de0| 74 68 20 74 68 65 20 6e | 6f 72 6d 61 6c 20 70 72 |th the n|ormal pr|
|00000df0| 6f 63 65 73 73 0d 0d 57 | 68 69 6c 65 20 74 68 61 |ocess..W|hile tha|
|00000e00| 74 20 74 61 6b 65 73 20 | 63 61 72 65 20 6f 66 20 |t takes |care of |
|00000e10| 6d 61 6b 69 6e 67 20 79 | 6f 75 72 20 63 6f 64 65 |making y|our code|
|00000e20| 20 66 61 69 6c 2d 70 72 | 6f 6f 66 2c 0d 69 74 20 | fail-pr|oof,.it |
|00000e30| 64 6f 65 73 20 6e 6f 74 | 20 74 65 6c 6c 20 74 68 |does not| tell th|
|00000e40| 65 20 63 61 6c 6c 65 72 | 20 74 68 61 74 20 68 65 |e caller| that he|
|00000e50| 20 64 69 64 6e 27 74 20 | 6d 65 65 74 20 79 6f 75 | didn't |meet you|
|00000e60| 72 0d 63 6f 6e 64 69 74 | 69 6f 6e 73 2e 0d 0d 59 |r.condit|ions...Y|
|00000e70| 6f 75 20 63 6f 75 6c 64 | 20 65 69 74 68 65 72 20 |ou could| either |
|00000e80| 68 61 6e 64 6c 65 20 74 | 68 61 74 20 62 79 20 72 |handle t|hat by r|
|00000e90| 65 74 75 72 6e 69 6e 67 | 20 73 6f 6d 65 20 76 61 |eturning| some va|
|00000ea0| 6c 75 65 0d 74 68 61 74 | 20 74 65 6c 6c 73 20 74 |lue.that| tells t|
|00000eb0| 68 65 20 63 61 6c 6c 65 | 72 20 77 68 65 74 68 65 |he calle|r whethe|
|00000ec0| 72 20 68 65 20 64 69 64 | 20 65 76 65 72 79 74 68 |r he did| everyth|
|00000ed0| 69 6e 67 20 72 69 67 68 | 74 0d 6f 72 20 6e 6f 74 |ing righ|t.or not|
|00000ee0| 2e 20 48 6f 77 65 76 65 | 72 2c 20 74 68 61 74 20 |. Howeve|r, that |
|00000ef0| 72 65 71 75 69 72 65 73 | 20 74 68 61 74 20 74 68 |requires| that th|
|00000f00| 65 20 63 61 6c 6c 65 72 | 20 6e 6f 74 0d 6f 6e 6c |e caller| not.onl|
|00000f10| 79 20 61 64 64 73 20 63 | 6f 64 65 20 74 6f 20 72 |y adds c|ode to r|
|00000f20| 65 74 72 69 65 76 65 20 | 74 68 61 74 20 61 64 64 |etrieve |that add|
|00000f30| 69 74 69 6f 6e 61 6c 20 | 72 65 74 75 72 6e 0d 76 |itional |return.v|
|00000f40| 61 6c 75 65 2c 20 62 75 | 74 20 74 68 61 74 20 68 |alue, bu|t that h|
|00000f50| 65 20 61 6c 73 6f 20 63 | 68 65 63 6b 73 20 74 68 |e also c|hecks th|
|00000f60| 65 20 76 61 6c 75 65 20 | 61 6e 64 20 68 61 6e 64 |e value |and hand|
|00000f70| 6c 65 73 0d 69 74 20 61 | 63 63 6f 72 64 69 6e 67 |les.it a|ccording|
|00000f80| 6c 79 2e 0d 0d 4f 72 2c | 20 79 6f 75 20 63 6f 75 |ly...Or,| you cou|
|00000f90| 6c 64 20 73 69 6d 70 6c | 79 20 73 69 67 6e 61 6c |ld simpl|y signal|
|00000fa0| 20 74 68 65 20 65 72 72 | 6f 72 20 63 6f 6e 64 69 | the err|or condi|
|00000fb0| 74 69 6f 6e 0d 62 79 20 | 75 73 69 6e 67 20 74 68 |tion.by |using th|
|00000fc0| 65 20 4d 73 67 42 6f 78 | 28 29 20 70 72 6f 63 65 |e MsgBox|() proce|
|00000fd0| 64 75 72 65 20 6c 69 6b | 65 20 74 68 69 73 3a 0d |dure lik|e this:.|
|00000fe0| 0d 20 20 49 46 20 70 6f | 73 4e 75 6d 20 3c 20 30 |. IF po|sNum < 0|
|00000ff0| 20 54 48 45 4e 0d 20 20 | 20 20 4d 73 67 42 6f 78 | THEN. | MsgBox|
|00001000| 20 22 65 72 72 6f 72 20 | 69 6e 20 41 64 64 4c 69 | "error |in AddLi|
|00001010| 6e 65 54 6f 54 65 78 74 | 66 69 6c 65 3a 20 70 6f |neToText|file: po|
|00001020| 73 4e 75 6d 20 3c 20 30 | 21 22 0d 20 20 20 20 52 |sNum < 0|!". R|
|00001030| 45 54 55 52 4e 0d 20 20 | 45 4e 44 0d 0d 54 68 61 |ETURN. |END..Tha|
|00001040| 74 2c 20 68 6f 77 65 76 | 65 72 2c 20 69 73 20 6e |t, howev|er, is n|
|00001050| 6f 74 20 72 65 63 6f 6d | 6d 65 6e 64 65 64 2c 20 |ot recom|mended, |
|00001060| 62 65 63 61 75 73 65 0d | 2a 20 68 61 72 64 2d 63 |because.|* hard-c|
|00001070| 6f 64 65 64 20 74 65 78 | 74 20 69 73 20 68 61 72 |oded tex|t is har|
|00001080| 64 20 74 6f 20 6c 6f 63 | 61 6c 69 7a 65 20 66 6f |d to loc|alize fo|
|00001090| 72 20 66 6f 72 65 69 67 | 6e 0d 20 20 6c 61 6e 67 |r foreig|n. lang|
|000010a0| 75 61 67 65 73 2c 0d 2a | 20 74 68 65 20 63 61 6c |uages,.*| the cal|
|000010b0| 6c 65 72 20 6d 69 67 68 | 74 20 6e 6f 74 20 65 78 |ler migh|t not ex|
|000010c0| 70 65 63 74 20 61 74 20 | 61 6c 6c 20 74 68 61 74 |pect at |all that|
|000010d0| 20 61 20 66 69 6c 65 2d | 0d 20 20 61 63 63 65 73 | a file-|. acces|
|000010e0| 73 69 6e 67 20 66 75 6e | 63 74 69 6f 6e 20 63 61 |sing fun|ction ca|
|000010f0| 6e 20 63 61 75 73 65 20 | 61 20 75 73 65 72 20 69 |n cause |a user i|
|00001100| 6e 74 65 72 61 63 74 69 | 6f 6e 2c 0d 2a 20 74 68 |nteracti|on,.* th|
|00001110| 65 20 63 61 6c 6c 65 72 | 20 73 74 69 6c 6c 20 69 |e caller| still i|
|00001120| 73 6e 27 74 20 61 62 6c | 65 20 74 6f 20 68 61 6e |sn't abl|e to han|
|00001130| 64 6c 65 20 74 68 65 20 | 65 72 72 6f 72 0d 20 20 |dle the |error. |
|00001140| 63 6f 6e 64 69 74 69 6f | 6e 20 62 79 20 68 69 6d |conditio|n by him|
|00001150| 73 65 6c 66 2e 0d 0d 52 | 61 69 73 69 6e 67 20 61 |self...R|aising a|
|00001160| 6e 20 45 78 63 65 70 74 | 69 6f 6e 20 73 6f 6c 76 |n Except|ion solv|
|00001170| 65 64 20 61 6c 6c 20 74 | 68 65 73 65 20 70 72 6f |ed all t|hese pro|
|00001180| 62 6c 65 6d 73 2e 0d 48 | 65 72 65 27 73 20 68 6f |blems..H|ere's ho|
|00001190| 77 20 69 74 20 77 6f 75 | 6c 64 20 6c 6f 6f 6b 20 |w it wou|ld look |
|000011a0| 6c 69 6b 65 20 69 6e 20 | 79 6f 75 72 20 63 6f 64 |like in |your cod|
|000011b0| 65 3a 0d 0d 20 20 49 46 | 20 70 6f 73 4e 75 6d 20 |e:.. IF| posNum |
|000011c0| 3c 20 30 20 54 48 45 4e | 0d 20 20 20 20 52 61 69 |< 0 THEN|. Rai|
|000011d0| 73 65 20 6e 65 77 20 52 | 75 6e 74 69 6d 65 45 78 |se new R|untimeEx|
|000011e0| 63 65 70 74 69 6f 6e 0d | 20 20 45 4e 44 0d 20 20 |ception.| END. |
|000011f0| 49 46 20 66 69 6c 65 52 | 65 66 20 3d 20 4e 49 4c |IF fileR|ef = NIL|
|00001200| 20 54 48 45 4e 0d 20 20 | 20 20 52 61 69 73 65 20 | THEN. | Raise |
|00001210| 6e 65 77 20 52 75 6e 74 | 69 6d 65 45 78 63 65 70 |new Runt|imeExcep|
|00001220| 74 69 6f 6e 0d 20 20 45 | 4e 44 0d 0d 49 66 20 79 |tion. E|ND..If y|
|00001230| 6f 75 20 72 61 69 73 65 | 20 61 6e 20 45 78 63 65 |ou raise| an Exce|
|00001240| 70 74 69 6f 6e 20 69 6e | 20 79 6f 75 72 20 63 6f |ption in| your co|
|00001250| 64 65 2c 20 69 74 20 77 | 6f 72 6b 73 0d 6c 69 6b |de, it w|orks.lik|
|00001260| 65 20 74 68 69 73 3a 20 | 46 69 72 73 74 2c 20 69 |e this: |First, i|
|00001270| 74 20 61 63 74 73 20 61 | 73 20 69 66 20 79 6f 75 |t acts a|s if you|
|00001280| 20 68 61 64 20 75 73 65 | 64 20 74 68 65 20 52 45 | had use|d the RE|
|00001290| 54 55 52 4e 0d 73 74 61 | 74 65 6d 65 6e 74 20 69 |TURN.sta|tement i|
|000012a0| 6e 73 74 65 61 64 3a 20 | 54 68 65 20 70 72 6f 63 |nstead: |The proc|
|000012b0| 65 64 75 72 65 20 77 69 | 6c 6c 20 62 65 20 65 78 |edure wi|ll be ex|
|000012c0| 69 74 65 64 2e 0d 41 6e | 64 20 68 65 72 65 20 63 |ited..An|d here c|
|000012d0| 6f 6d 65 73 20 74 68 65 | 20 73 6d 61 72 74 20 70 |omes the| smart p|
|000012e0| 61 72 74 3a 20 49 66 20 | 74 68 65 20 63 61 6c 6c |art: If |the call|
|000012f0| 69 6e 67 0d 70 72 6f 63 | 65 64 75 72 65 20 64 6f |ing.proc|edure do|
|00001300| 65 73 20 6e 6f 74 20 65 | 78 70 6c 69 63 69 74 6c |es not e|xplicitl|
|00001310| 79 20 68 61 6e 64 6c 65 | 20 74 68 65 20 65 78 63 |y handle| the exc|
|00001320| 65 70 74 69 6f 6e 2c 0d | 69 74 20 77 69 6c 6c 20 |eption,.|it will |
|00001330| 6e 6f 74 20 67 65 74 20 | 66 6f 72 67 6f 74 74 65 |not get |forgotte|
|00001340| 6e 20 28 61 73 20 69 6e | 20 74 68 65 20 63 61 73 |n (as in| the cas|
|00001350| 65 20 77 68 65 6e 20 79 | 6f 75 0d 68 61 64 20 72 |e when y|ou.had r|
|00001360| 65 74 75 72 6e 65 64 20 | 61 20 73 75 63 63 65 73 |eturned |a succes|
|00001370| 73 20 76 61 6c 75 65 29 | 2c 20 62 75 74 20 77 69 |s value)|, but wi|
|00001380| 6c 6c 20 67 65 74 20 70 | 61 73 73 65 64 0d 6f 6e |ll get p|assed.on|
|00001390| 20 74 6f 20 69 74 73 20 | 63 61 6c 6c 65 72 2c 20 | to its |caller, |
|000013a0| 61 6e 64 20 74 68 65 6e | 20 74 6f 20 74 68 61 74 |and then| to that|
|000013b0| 20 6f 6e 65 27 73 20 63 | 61 6c 6c 65 72 2c 0d 61 | one's c|aller,.a|
|000013c0| 6e 64 20 73 6f 20 6f 6e | 2c 20 75 6e 74 69 6c 20 |nd so on|, until |
|000013d0| 61 74 20 6f 6e 65 20 6f | 75 74 73 69 64 65 20 70 |at one o|utside p|
|000013e0| 72 6f 63 65 64 75 72 65 | 20 74 68 65 0d 65 78 63 |rocedure| the.exc|
|000013f0| 65 70 74 69 6f 6e 20 69 | 73 20 74 61 6b 65 6e 20 |eption i|s taken |
|00001400| 63 61 72 65 20 6f 66 2e | 20 49 66 20 6e 6f 20 6f |care of.| If no o|
|00001410| 6e 65 20 68 61 6e 64 6c | 65 73 20 74 68 65 0d 65 |ne handl|es the.e|
|00001420| 78 63 65 70 74 69 6f 6e | 20 65 78 70 6c 69 63 69 |xception| explici|
|00001430| 74 6c 79 2c 20 52 42 20 | 77 69 6c 6c 20 69 6e 76 |tly, RB |will inv|
|00001440| 6f 6b 65 20 61 20 73 74 | 61 6e 64 61 72 64 0d 65 |oke a st|andard.e|
|00001450| 72 72 6f 72 20 64 69 61 | 6c 6f 67 20 74 68 61 74 |rror dia|log that|
|00001460| 20 73 74 6f 70 73 20 65 | 78 65 63 75 74 69 6f 6e | stops e|xecution|
|00001470| 20 6f 66 20 79 6f 75 72 | 20 61 70 70 6c 69 63 61 | of your| applica|
|00001480| 74 69 6f 6e 0d 61 6e 64 | 20 73 68 6f 77 73 20 79 |tion.and| shows y|
|00001490| 6f 75 20 74 68 65 20 65 | 72 72 6f 72 20 63 6f 6e |ou the e|rror con|
|000014a0| 64 69 74 69 6f 6e 20 69 | 6e 20 74 68 65 20 65 64 |dition i|n the ed|
|000014b0| 69 74 6f 72 2e 0d 0d 0d | 48 61 6e 64 6c 69 6e 67 |itor....|Handling|
|000014c0| 20 45 78 63 65 70 74 69 | 6f 6e 73 0d 2d 2d 2d 2d | Excepti|ons.----|
|000014d0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 0d |--------|-------.|
|000014e0| 0d 53 6f 2c 20 74 6f 20 | 68 61 6e 64 6c 65 20 74 |.So, to |handle t|
|000014f0| 68 65 20 65 78 63 65 70 | 74 69 6f 6e 2c 20 79 6f |he excep|tion, yo|
|00001500| 75 27 6c 6c 20 68 61 76 | 65 20 74 6f 20 61 64 64 |u'll hav|e to add|
|00001510| 0d 61 20 73 6f 2d 63 61 | 6c 6c 65 64 20 65 78 65 |.a so-ca|lled exe|
|00001520| 70 74 69 6f 6e 20 68 61 | 6e 64 6c 65 72 20 74 6f |ption ha|ndler to|
|00001530| 20 74 68 65 20 65 6e 64 | 20 6f 66 20 79 6f 75 72 | the end| of your|
|00001540| 0d 70 72 6f 63 65 64 75 | 72 65 3a 0d 0d 20 20 53 |.procedu|re:.. S|
|00001550| 75 62 20 57 72 69 74 65 | 53 6f 6d 65 4c 69 6e 65 |ub Write|SomeLine|
|00001560| 73 54 6f 41 46 69 6c 65 | 28 29 0d 20 20 20 20 2e |sToAFile|(). .|
|00001570| 2e 2e 0d 20 20 45 78 63 | 65 70 74 69 6f 6e 20 65 |... Exc|eption e|
|00001580| 78 63 20 61 73 20 52 75 | 6e 74 69 6d 65 45 78 63 |xc as Ru|ntimeExc|
|00001590| 65 70 74 69 6f 6e 0d 20 | 20 20 20 4d 73 67 42 6f |eption. | MsgBo|
|000015a0| 78 20 22 6f 6f 70 73 20 | 2d 20 74 68 65 72 65 27 |x "oops |- there'|
|000015b0| 73 20 73 6f 6d 65 74 68 | 69 6e 67 20 77 72 6f 6e |s someth|ing wron|
|000015c0| 67 22 0d 20 20 45 6e 64 | 20 53 75 62 0d 0d 43 61 |g". End| Sub..Ca|
|000015d0| 74 63 68 69 6e 67 20 65 | 78 63 65 70 74 69 6f 6e |tching e|xception|
|000015e0| 73 20 61 73 20 73 65 65 | 6e 20 61 62 6f 76 65 20 |s as see|n above |
|000015f0| 69 73 20 74 68 65 20 6d | 6f 73 74 20 67 65 6e 65 |is the m|ost gene|
|00001600| 72 69 63 0d 77 61 79 20 | 6f 66 20 63 61 74 63 68 |ric.way |of catch|
|00001610| 69 6e 67 20 61 6e 79 20 | 65 78 63 65 70 74 69 6f |ing any |exceptio|
|00001620| 6e 73 20 69 6e 20 79 6f | 75 72 20 61 70 70 6c 69 |ns in yo|ur appli|
|00001630| 63 61 74 69 6f 6e 2c 0d | 69 6e 63 6c 75 64 69 6e |cation,.|includin|
|00001640| 67 20 63 61 73 65 73 20 | 6f 66 20 75 73 69 6e 67 |g cases |of using|
|00001650| 20 61 20 6e 6f 6e 2d 65 | 78 69 73 74 69 6e 67 73 | a non-e|xistings|
|00001660| 20 4f 62 6a 65 63 74 20 | 28 68 61 70 70 65 6e 73 | Object |(happens|
|00001670| 0d 77 68 65 6e 20 61 6e | 20 6f 62 6a 65 63 74 20 |.when an| object |
|00001680| 72 65 66 65 72 65 6e 63 | 65 20 69 73 20 4e 49 4c |referenc|e is NIL|
|00001690| 29 2c 20 61 20 73 74 61 | 63 6b 20 6f 76 65 72 66 |), a sta|ck overf|
|000016a0| 6c 6f 77 0d 28 68 61 70 | 70 65 6e 73 20 77 68 65 |low.(hap|pens whe|
|000016b0| 6e 20 73 75 62 72 6f 75 | 74 69 6e 65 73 20 61 72 |n subrou|tines ar|
|000016c0| 65 20 74 6f 6f 20 64 65 | 65 70 6c 79 20 6e 65 73 |e too de|eply nes|
|000016d0| 74 65 64 2c 0d 65 73 70 | 65 63 69 61 6c 6c 79 20 |ted,.esp|ecially |
|000016e0| 69 6e 20 72 65 63 75 72 | 73 69 76 65 20 63 61 6c |in recur|sive cal|
|000016f0| 6c 69 6e 67 29 2c 20 61 | 6e 64 20 61 72 72 61 79 |ling), a|nd array|
|00001700| 20 69 6e 64 65 78 69 6e | 67 0d 65 72 72 6f 72 73 | indexin|g.errors|
|00001710| 20 28 77 68 65 6e 20 74 | 68 65 20 61 64 64 72 65 | (when t|he addre|
|00001720| 73 73 65 64 20 61 72 72 | 61 79 20 65 6c 65 6d 65 |ssed arr|ay eleme|
|00001730| 6e 74 20 69 73 20 6f 75 | 74 20 6f 66 0d 69 74 73 |nt is ou|t of.its|
|00001740| 20 62 6f 75 6e 64 73 29 | 2e 0d 0d 57 68 65 6e 20 | bounds)|...When |
|00001750| 79 6f 75 20 61 64 64 20 | 73 75 63 68 20 63 6f 64 |you add |such cod|
|00001760| 65 20 74 6f 20 61 6c 6c | 20 6f 66 20 79 6f 75 72 |e to all| of your|
|00001770| 20 79 6f 75 72 20 65 76 | 65 6e 74 0d 68 61 6e 64 | your ev|ent.hand|
|00001780| 6c 65 72 20 72 6f 75 74 | 69 6e 65 73 2c 20 79 6f |ler rout|ines, yo|
|00001790| 75 20 77 69 6c 6c 20 62 | 65 20 61 62 6c 65 20 74 |u will b|e able t|
|000017a0| 6f 20 74 72 61 70 20 61 | 6e 79 0d 65 72 72 6f 72 |o trap a|ny.error|
|000017b0| 20 63 6f 6e 64 69 74 69 | 6f 6e 73 20 69 6e 20 79 | conditi|ons in y|
|000017c0| 6f 75 72 20 61 70 70 6c | 69 63 61 74 69 6f 6e 20 |our appl|ication |
|000017d0| 61 6e 79 20 67 72 61 63 | 65 66 75 6c 6c 79 0d 68 |any grac|efully.h|
|000017e0| 61 6e 64 6c 69 6e 67 20 | 74 68 65 6d 20 69 6e 73 |andling |them ins|
|000017f0| 74 65 61 64 20 6f 66 20 | 68 61 76 69 6e 67 20 79 |tead of |having y|
|00001800| 6f 75 72 20 61 70 70 6c | 69 63 61 74 69 6f 6e 0d |our appl|ication.|
|00001810| 61 75 74 6f 6d 61 74 69 | 63 61 6c 6c 79 20 71 75 |automati|cally qu|
|00001820| 69 74 20 65 61 63 68 20 | 74 69 6d 65 20 73 75 63 |it each |time suc|
|00001830| 68 20 61 20 65 78 63 65 | 70 74 69 6f 6e 20 6f 63 |h a exce|ption oc|
|00001840| 63 75 72 73 2e 0d 0d 0d | 43 72 65 61 74 69 6e 67 |curs....|Creating|
|00001850| 20 79 6f 75 72 20 6f 77 | 6e 20 45 78 63 65 70 74 | your ow|n Except|
|00001860| 69 6f 6e 20 74 79 70 65 | 73 0d 2d 2d 2d 2d 2d 2d |ion type|s.------|
|00001870| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00001880| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 0d 0d 52 61 69 |--------|---..Rai|
|00001890| 73 69 6e 67 20 61 20 22 | 52 75 6e 74 69 6d 65 45 |sing a "|RuntimeE|
|000018a0| 78 63 65 70 74 69 6f 6e | 22 20 69 73 20 61 20 67 |xception|" is a g|
|000018b0| 65 6e 65 72 69 63 20 61 | 6e 64 0d 71 75 69 74 65 |eneric a|nd.quite|
|000018c0| 20 75 6e 73 70 65 63 69 | 66 69 63 20 6d 65 73 73 | unspeci|fic mess|
|000018d0| 61 67 65 20 74 6f 20 74 | 68 65 20 63 61 6c 6c 65 |age to t|he calle|
|000018e0| 72 2e 20 49 74 20 77 6f | 75 6c 64 20 62 65 0d 6e |r. It wo|uld be.n|
|000018f0| 69 63 65 72 20 69 66 20 | 74 68 65 20 73 75 62 72 |icer if |the subr|
|00001900| 6f 75 74 69 6e 65 20 63 | 61 6e 20 72 61 69 73 65 |outine c|an raise|
|00001910| 20 69 74 73 20 65 78 63 | 65 70 74 69 6f 6e 73 0d | its exc|eptions.|
|00001920| 77 69 74 68 20 73 6f 6d | 65 20 6d 6f 72 65 20 69 |with som|e more i|
|00001930| 6e 66 6f 72 6d 61 74 69 | 6f 6e 2c 20 6c 69 6b 65 |nformati|on, like|
|00001940| 20 61 20 74 65 78 74 20 | 6d 65 73 73 61 67 65 0d | a text |message.|
|00001950| 65 78 70 6c 61 69 6e 69 | 6e 67 20 74 68 65 20 65 |explaini|ng the e|
|00001960| 72 72 6f 72 20 63 6f 6e | 64 69 74 69 6f 6e 20 69 |rror con|dition i|
|00001970| 6e 20 6d 6f 72 65 20 64 | 65 74 61 69 6c 20 6f 72 |n more d|etail or|
|00001980| 0d 65 76 65 6e 20 67 69 | 76 69 6e 67 20 6d 6f 72 |.even gi|ving mor|
|00001990| 65 20 69 6e 66 6f 72 6d | 61 74 69 6f 6e 20 61 62 |e inform|ation ab|
|000019a0| 6f 75 74 20 74 68 65 20 | 70 61 72 61 6d 65 74 65 |out the |paramete|
|000019b0| 72 73 0d 74 68 61 74 20 | 61 72 65 20 62 6f 75 6e |rs.that |are boun|
|000019c0| 64 20 74 6f 20 74 68 65 | 20 63 6f 6e 64 69 74 69 |d to the| conditi|
|000019d0| 6f 6e 20 28 6c 69 6b 65 | 20 74 68 65 20 66 69 6c |on (like| the fil|
|000019e0| 65 20 6e 61 6d 65 0d 6f | 72 20 74 68 65 20 76 61 |e name.o|r the va|
|000019f0| 6c 75 65 20 6f 66 20 74 | 68 65 20 6e 6f 6e 2d 70 |lue of t|he non-p|
|00001a00| 6f 73 69 74 69 76 65 20 | 6e 75 6d 62 65 72 29 2e |ositive |number).|
|00001a10| 0d 0d 46 6f 72 20 74 68 | 61 74 2c 20 77 65 20 68 |..For th|at, we h|
|00001a20| 61 76 65 20 74 6f 20 63 | 72 65 61 74 65 20 61 20 |ave to c|reate a |
|00001a30| 6e 65 77 20 73 75 62 63 | 6c 61 73 73 20 6f 66 0d |new subc|lass of.|
|00001a40| 61 20 22 52 75 6e 74 69 | 6d 65 45 78 63 65 70 74 |a "Runti|meExcept|
|00001a50| 69 6f 6e 22 20 63 6c 61 | 73 73 3a 20 49 6e 20 74 |ion" cla|ss: In t|
|00001a60| 68 65 20 52 42 20 65 64 | 69 74 6f 72 2c 0d 63 72 |he RB ed|itor,.cr|
|00001a70| 65 61 74 65 20 61 20 6e | 65 77 20 63 6c 61 73 73 |eate a n|ew class|
|00001a80| 2c 20 6e 61 6d 65 20 69 | 74 20 22 4d 79 53 70 65 |, name i|t "MySpe|
|00001a90| 63 69 61 6c 45 78 63 65 | 70 74 69 6f 6e 22 0d 61 |cialExce|ption".a|
|00001aa0| 6e 64 20 73 65 74 20 69 | 74 73 20 53 75 70 65 72 |nd set i|ts Super|
|00001ab0| 20 63 6c 61 73 73 20 74 | 6f 20 52 75 6e 74 69 6d | class t|o Runtim|
|00001ac0| 65 45 78 63 65 70 74 69 | 6f 6e 2e 0d 0d 4e 6f 77 |eExcepti|on...Now|
|00001ad0| 2c 20 69 6e 73 74 65 61 | 64 20 6f 66 20 72 61 69 |, instea|d of rai|
|00001ae0| 73 69 6e 67 20 61 20 52 | 75 6e 74 69 6d 65 45 78 |sing a R|untimeEx|
|00001af0| 63 65 70 74 69 6f 6e 2c | 0d 77 65 20 63 61 6e 20 |ception,|.we can |
|00001b00| 72 61 69 73 65 20 6f 75 | 72 20 6f 77 6e 20 6f 6e |raise ou|r own on|
|00001b10| 65 3a 0d 0d 20 20 49 46 | 20 70 6f 73 4e 75 6d 20 |e:.. IF| posNum |
|00001b20| 3c 20 30 20 54 48 45 4e | 0d 20 20 20 20 52 61 69 |< 0 THEN|. Rai|
|00001b30| 73 65 20 6e 65 77 20 4d | 79 53 70 65 63 69 61 6c |se new M|ySpecial|
|00001b40| 45 78 63 65 70 74 69 6f | 6e 0d 20 20 45 4e 44 0d |Exceptio|n. END.|
|00001b50| 0d 49 6e 20 61 6e 20 65 | 78 63 65 70 74 69 6f 6e |.In an e|xception|
|00001b60| 20 68 61 6e 64 6c 65 72 | 2c 20 77 65 20 63 61 6e | handler|, we can|
|00001b70| 20 6d 61 6b 65 20 75 73 | 65 20 6f 66 20 74 68 69 | make us|e of thi|
|00001b80| 73 3a 0d 0d 20 20 45 78 | 63 65 70 74 69 6f 6e 20 |s:.. Ex|ception |
|00001b90| 65 78 63 20 61 73 20 52 | 75 6e 74 69 6d 65 45 78 |exc as R|untimeEx|
|00001ba0| 63 65 70 74 69 6f 6e 0d | 20 20 20 20 49 46 20 65 |ception.| IF e|
|00001bb0| 78 63 20 69 73 41 20 4d | 79 53 70 65 63 69 61 6c |xc isA M|ySpecial|
|00001bc0| 45 78 63 65 70 74 69 6f | 6e 20 54 48 45 4e 0d 20 |Exceptio|n THEN. |
|00001bd0| 20 20 20 20 20 4d 73 67 | 42 6f 78 20 22 6f 6f 70 | Msg|Box "oop|
|00001be0| 73 20 2d 20 41 64 64 4c | 69 6e 65 54 6f 54 65 78 |s - AddL|ineToTex|
|00001bf0| 74 66 69 6c 65 20 66 61 | 69 6c 65 64 22 0d 20 20 |tfile fa|iled". |
|00001c00| 20 20 45 4c 53 45 0d 20 | 20 20 20 20 20 4d 73 67 | ELSE. | Msg|
|00001c10| 42 6f 78 20 22 6f 6f 70 | 73 20 2d 20 74 68 65 72 |Box "oop|s - ther|
|00001c20| 65 27 73 20 73 6f 6d 65 | 74 68 69 6e 67 20 65 6c |e's some|thing el|
|00001c30| 73 65 20 77 72 6f 6e 67 | 22 0d 20 20 20 20 45 4e |se wrong|". EN|
|00001c40| 44 0d 20 20 45 6e 64 20 | 53 75 62 0d 0d 4e 6f 77 |D. End |Sub..Now|
|00001c50| 2c 20 73 69 6e 63 65 20 | 77 65 20 64 6f 20 6e 6f |, since |we do no|
|00001c60| 74 20 77 61 6e 74 20 74 | 6f 20 68 61 6e 64 6c 65 |t want t|o handle|
|00001c70| 20 74 68 6f 73 65 20 75 | 6e 6b 6e 6f 77 6e 0d 65 | those u|nknown.e|
|00001c80| 78 63 65 70 74 69 6f 6e | 73 20 69 6e 20 6f 75 72 |xception|s in our|
|00001c90| 20 57 72 69 74 65 53 6f | 6d 65 4c 69 6e 65 73 54 | WriteSo|meLinesT|
|00001ca0| 6f 41 46 69 6c 65 20 70 | 72 6f 63 65 64 75 72 65 |oAFile p|rocedure|
|00001cb0| 2c 0d 62 75 74 20 6f 6e | 6c 79 20 74 68 65 20 65 |,.but on|ly the e|
|00001cc0| 78 63 65 70 74 69 6f 6e | 73 20 74 68 61 74 20 77 |xception|s that w|
|00001cd0| 65 20 61 72 65 20 61 77 | 61 72 65 20 6f 66 20 28 |e are aw|are of (|
|00001ce0| 74 68 6f 73 65 0d 65 78 | 70 6c 69 63 69 74 6c 79 |those.ex|plicitly|
|00001cf0| 20 72 61 69 73 65 64 20 | 69 6e 20 41 64 64 4c 69 | raised |in AddLi|
|00001d00| 6e 65 54 6f 54 65 78 74 | 66 69 6c 65 29 2c 0d 77 |neToText|file),.w|
|00001d10| 65 20 63 61 6e 20 70 61 | 73 73 20 74 68 65 20 6f |e can pa|ss the o|
|00001d20| 74 68 65 72 20 65 78 63 | 65 70 74 69 6f 6e 73 20 |ther exc|eptions |
|00001d30| 75 70 20 74 6f 20 68 69 | 67 68 65 72 0d 6c 65 76 |up to hi|gher.lev|
|00001d40| 65 6c 73 20 69 6e 20 74 | 68 65 20 63 61 6c 6c 69 |els in t|he calli|
|00001d50| 6e 67 20 73 74 61 63 6b | 20 62 79 20 72 61 69 73 |ng stack| by rais|
|00001d60| 69 6e 67 20 74 68 65 6d | 20 61 67 61 69 6e 3a 0d |ing them| again:.|
|00001d70| 0d 20 20 45 78 63 65 70 | 74 69 6f 6e 20 65 78 63 |. Excep|tion exc|
|00001d80| 20 61 73 20 52 75 6e 74 | 69 6d 65 45 78 63 65 70 | as Runt|imeExcep|
|00001d90| 74 69 6f 6e 0d 20 20 20 | 20 49 46 20 65 78 63 20 |tion. | IF exc |
|00001da0| 69 73 41 20 4d 79 53 70 | 65 63 69 61 6c 45 78 63 |isA MySp|ecialExc|
|00001db0| 65 70 74 69 6f 6e 20 54 | 48 45 4e 0d 20 20 20 20 |eption T|HEN. |
|00001dc0| 20 20 4d 73 67 42 6f 78 | 20 22 6f 6f 70 73 20 2d | MsgBox| "oops -|
|00001dd0| 20 41 64 64 4c 69 6e 65 | 54 6f 54 65 78 74 66 69 | AddLine|ToTextfi|
|00001de0| 6c 65 20 66 61 69 6c 65 | 64 22 0d 20 20 20 20 45 |le faile|d". E|
|00001df0| 4c 53 45 0d 20 20 20 20 | 20 20 2f 2f 20 73 6f 6d |LSE. | // som|
|00001e00| 65 20 6f 74 68 65 72 20 | 65 78 63 65 70 74 69 6f |e other |exceptio|
|00001e10| 6e 20 2d 20 77 65 20 64 | 6f 6e 27 74 20 68 61 6e |n - we d|on't han|
|00001e20| 64 6c 65 20 74 68 61 74 | 20 68 65 72 65 0d 20 20 |dle that| here. |
|00001e30| 20 20 20 20 52 61 69 73 | 65 20 65 78 63 0d 20 20 | Rais|e exc. |
|00001e40| 20 20 45 4e 44 0d 20 20 | 45 6e 64 20 53 75 62 0d | END. |End Sub.|
|00001e50| 0d 41 73 20 61 20 73 68 | 6f 72 74 20 66 6f 72 6d |.As a sh|ort form|
|00001e60| 2c 20 74 68 65 20 61 62 | 6f 76 65 20 63 61 6e 20 |, the ab|ove can |
|00001e70| 62 65 20 77 72 69 74 74 | 65 6e 20 6c 69 6b 65 20 |be writt|en like |
|00001e80| 74 68 69 73 3a 0d 0d 20 | 20 45 78 63 65 70 74 69 |this:.. | Excepti|
|00001e90| 6f 6e 20 65 78 63 20 61 | 73 20 4d 79 53 70 65 63 |on exc a|s MySpec|
|00001ea0| 69 61 6c 45 78 63 65 70 | 74 69 6f 6e 0d 20 20 20 |ialExcep|tion. |
|00001eb0| 20 4d 73 67 42 6f 78 20 | 22 6f 6f 70 73 20 2d 20 | MsgBox |"oops - |
|00001ec0| 41 64 64 4c 69 6e 65 54 | 6f 54 65 78 74 66 69 6c |AddLineT|oTextfil|
|00001ed0| 65 20 66 61 69 6c 65 64 | 22 0d 20 20 45 6e 64 20 |e failed|". End |
|00001ee0| 53 75 62 0d 0d 28 74 68 | 69 73 20 6d 65 61 6e 73 |Sub..(th|is means|
|00001ef0| 20 74 68 61 74 20 6f 6e | 6c 79 20 65 78 63 65 70 | that on|ly excep|
|00001f00| 74 69 6f 6e 73 20 6f 66 | 20 74 79 70 65 20 4d 79 |tions of| type My|
|00001f10| 53 70 65 63 69 61 6c 45 | 78 63 65 70 74 69 6f 6e |SpecialE|xception|
|00001f20| 0d 61 72 65 20 68 61 6e | 64 6c 65 64 20 68 65 72 |.are han|dled her|
|00001f30| 65 2c 20 61 6c 6c 20 6f | 74 68 65 72 73 20 61 72 |e, all o|thers ar|
|00001f40| 65 20 70 61 73 73 65 64 | 20 6f 6e 20 74 6f 20 68 |e passed| on to h|
|00001f50| 69 67 68 65 72 20 6c 65 | 76 65 6c 73 2e 29 0d 0d |igher le|vels.)..|
|00001f60| 0d 41 64 64 69 6e 67 20 | 6d 6f 72 65 20 69 6e 66 |.Adding |more inf|
|00001f70| 6f 72 6d 61 74 69 6f 6e | 20 74 6f 20 45 78 63 65 |ormation| to Exce|
|00001f80| 70 74 69 6f 6e 73 20 79 | 6f 75 20 72 61 69 73 65 |ptions y|ou raise|
|00001f90| 0d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |.-------|--------|
|00001fa0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00001fb0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00001fc0| 0d 0d 54 68 61 6e 6b 73 | 20 74 6f 20 74 68 65 20 |..Thanks| to the |
|00001fd0| 63 6f 6e 63 65 70 74 73 | 20 6f 66 20 4f 62 6a 65 |concepts| of Obje|
|00001fe0| 63 74 20 4f 72 69 65 6e | 74 65 64 20 70 72 6f 67 |ct Orien|ted prog|
|00001ff0| 72 61 6d 6d 69 6e 67 0d | 61 6e 64 20 74 6f 20 74 |ramming.|and to t|
|00002000| 68 65 20 66 61 63 74 20 | 74 68 61 74 20 61 6e 20 |he fact |that an |
|00002010| 45 78 63 65 70 74 69 6f | 6e 20 69 73 20 61 6e 20 |Exceptio|n is an |
|00002020| 6f 62 6a 65 63 74 2c 20 | 74 6f 6f 2c 0d 77 65 20 |object, |too,.we |
|00002030| 63 61 6e 20 62 65 6e 65 | 66 69 74 20 66 72 6f 6d |can bene|fit from|
|00002040| 20 74 68 69 73 20 62 79 | 20 6d 61 6b 69 6e 67 20 | this by| making |
|00002050| 6f 75 72 20 65 78 63 65 | 70 74 69 6f 6e 20 73 69 |our exce|ption si|
|00002060| 67 6e 61 6c 6c 69 6e 67 | 0d 65 76 65 6e 20 73 6d |gnalling|.even sm|
|00002070| 61 72 74 65 72 20 61 6e | 64 20 71 75 69 74 65 20 |arter an|d quite |
|00002080| 75 6e 69 76 65 72 73 61 | 6c 3a 0d 0d 49 6e 20 74 |universa|l:..In t|
|00002090| 68 65 20 52 42 20 65 64 | 69 74 6f 72 2c 20 6c 65 |he RB ed|itor, le|
|000020a0| 74 27 73 20 61 64 64 20 | 61 20 70 72 6f 70 65 72 |t's add |a proper|
|000020b0| 74 79 20 74 6f 20 74 68 | 65 0d 4d 79 53 70 65 63 |ty to th|e.MySpec|
|000020c0| 69 61 6c 45 78 63 65 70 | 74 69 6f 6e 20 63 6c 61 |ialExcep|tion cla|
|000020d0| 73 73 2e 0d 0d 20 20 41 | 64 64 20 74 68 65 20 70 |ss... A|dd the p|
|000020e0| 72 6f 70 65 72 74 79 3a | 20 6d 73 67 20 61 73 20 |roperty:| msg as |
|000020f0| 53 74 72 69 6e 67 0d 0d | 4e 6f 77 2c 20 77 68 65 |String..|Now, whe|
|00002100| 6e 20 77 65 20 72 61 69 | 73 65 20 61 6e 20 65 78 |n we rai|se an ex|
|00002110| 63 65 70 74 69 6f 6e 20 | 6f 66 20 74 68 61 74 20 |ception |of that |
|00002120| 74 79 70 65 2c 20 77 65 | 0d 63 61 6e 20 61 64 64 |type, we|.can add|
|00002130| 20 73 6f 6d 65 20 69 6e | 66 6f 72 6d 61 74 69 6f | some in|formatio|
|00002140| 6e 20 69 6e 20 69 74 73 | 20 6d 73 67 20 70 72 6f |n in its| msg pro|
|00002150| 70 65 72 74 79 2c 20 6c | 69 6b 65 0d 74 68 69 73 |perty, l|ike.this|
|00002160| 3a 0d 0d 20 20 44 69 6d | 20 6d 79 45 78 63 20 61 |:.. Dim| myExc a|
|00002170| 73 20 4d 79 53 70 65 63 | 69 61 6c 45 78 63 65 70 |s MySpec|ialExcep|
|00002180| 74 69 6f 6e 20 0d 20 20 | 2e 2e 2e 0d 20 20 49 46 |tion . |.... IF|
|00002190| 20 66 69 6c 65 52 65 66 | 20 3d 20 6e 69 6c 20 54 | fileRef| = nil T|
|000021a0| 48 45 4e 0d 20 20 20 20 | 6d 79 45 78 63 20 3d 20 |HEN. |myExc = |
|000021b0| 6e 65 77 20 4d 79 53 70 | 65 63 69 61 6c 45 78 63 |new MySp|ecialExc|
|000021c0| 65 70 74 69 6f 6e 0d 20 | 20 20 20 6d 79 45 78 63 |eption. | myExc|
|000021d0| 2e 6d 73 67 20 3d 20 22 | 66 69 6c 65 52 65 66 20 |.msg = "|fileRef |
|000021e0| 3d 20 6e 69 6c 20 28 70 | 6f 73 4e 75 6d 20 3d 20 |= nil (p|osNum = |
|000021f0| 22 20 2b 20 53 74 72 28 | 70 6f 73 4e 75 6d 29 20 |" + Str(|posNum) |
|00002200| 2b 20 22 29 22 0d 20 20 | 20 20 52 61 69 73 65 20 |+ ")". | Raise |
|00002210| 6d 79 45 78 63 0d 20 20 | 45 4e 44 0d 20 20 49 46 |myExc. |END. IF|
|00002220| 20 70 6f 73 4e 75 6d 20 | 3c 20 30 20 54 48 45 4e | posNum |< 0 THEN|
|00002230| 0d 20 20 20 20 6d 79 45 | 78 63 20 3d 20 6e 65 77 |. myE|xc = new|
|00002240| 20 4d 79 53 70 65 63 69 | 61 6c 45 78 63 65 70 74 | MySpeci|alExcept|
|00002250| 69 6f 6e 0d 20 20 20 20 | 6d 79 45 78 63 2e 6d 73 |ion. |myExc.ms|
|00002260| 67 20 3d 20 22 66 69 6c | 65 20 22 20 2b 20 66 69 |g = "fil|e " + fi|
|00002270| 6c 65 52 65 66 2e 6e 61 | 6d 65 20 2b 20 22 3a 20 |leRef.na|me + ": |
|00002280| 70 6f 73 4e 75 6d 20 3c | 20 30 22 0d 20 20 20 20 |posNum <| 0". |
|00002290| 52 61 69 73 65 20 6d 79 | 45 78 63 0d 20 20 45 4e |Raise my|Exc. EN|
|000022a0| 44 0d 0d 54 68 65 20 65 | 78 63 65 70 74 69 6f 6e |D..The e|xception|
|000022b0| 20 68 61 6e 64 6c 65 72 | 20 74 68 65 6e 20 63 61 | handler| then ca|
|000022c0| 6e 20 75 73 65 20 74 68 | 61 74 20 6d 65 73 73 61 |n use th|at messa|
|000022d0| 67 65 3a 0d 0d 20 20 45 | 78 63 65 70 74 69 6f 6e |ge:.. E|xception|
|000022e0| 20 65 78 63 20 61 73 20 | 4d 79 53 70 65 63 69 61 | exc as |MySpecia|
|000022f0| 6c 45 78 63 65 70 74 69 | 6f 6e 0d 20 20 20 20 49 |lExcepti|on. I|
|00002300| 46 20 65 78 63 2e 6d 73 | 67 20 3d 20 22 22 20 54 |F exc.ms|g = "" T|
|00002310| 48 45 4e 0d 20 20 20 20 | 20 20 4d 73 67 42 6f 78 |HEN. | MsgBox|
|00002320| 20 22 6f 6f 70 73 20 2d | 20 41 64 64 4c 69 6e 65 | "oops -| AddLine|
|00002330| 54 6f 54 65 78 74 66 69 | 6c 65 20 66 61 69 6c 65 |ToTextfi|le faile|
|00002340| 64 20 66 6f 72 20 75 6e | 6b 6e 6f 77 6e 20 72 65 |d for un|known re|
|00002350| 61 73 6f 6e 2e 22 0d 20 | 20 20 20 45 4c 53 45 0d |ason.". | ELSE.|
|00002360| 20 20 20 20 20 20 4d 73 | 67 42 6f 78 20 22 6f 6f | Ms|gBox "oo|
|00002370| 70 73 20 2d 20 41 64 64 | 4c 69 6e 65 54 6f 54 65 |ps - Add|LineToTe|
|00002380| 78 74 66 69 6c 65 20 66 | 61 69 6c 65 64 3a 20 22 |xtfile f|ailed: "|
|00002390| 20 2b 20 65 78 63 2e 6d | 73 67 0d 20 20 20 20 45 | + exc.m|sg. E|
|000023a0| 4e 44 0d 20 20 45 6e 64 | 20 53 75 62 0d 0d 0d 4d |ND. End| Sub...M|
|000023b0| 61 6b 69 6e 67 20 79 6f | 75 72 20 6f 77 6e 20 73 |aking yo|ur own s|
|000023c0| 75 62 72 6f 75 74 69 6e | 65 73 20 73 61 66 65 72 |ubroutin|es safer|
|000023d0| 0d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |.-------|--------|
|000023e0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000023f0| 2d 2d 0d 0d 54 68 65 72 | 65 27 73 20 61 6e 6f 74 |--..Ther|e's anot|
|00002400| 68 65 72 20 70 72 6f 62 | 6c 65 6d 20 79 6f 75 20 |her prob|lem you |
|00002410| 63 61 6e 20 68 61 6e 64 | 6c 65 20 6e 69 63 65 6c |can hand|le nicel|
|00002420| 79 20 77 69 74 68 20 61 | 6e 0d 65 78 63 65 70 74 |y with a|n.except|
|00002430| 69 6f 6e 20 68 61 6e 64 | 6c 65 72 3a 20 49 6e 20 |ion hand|ler: In |
|00002440| 61 20 73 75 62 72 6f 75 | 74 69 6e 65 20 6f 66 20 |a subrou|tine of |
|00002450| 79 6f 75 72 73 2c 20 74 | 68 65 72 65 0d 63 61 6e |yours, t|here.can|
|00002460| 20 62 65 20 6d 61 6e 79 | 20 65 72 72 6f 72 20 63 | be many| error c|
|00002470| 6f 6e 64 69 74 69 6f 6e | 73 20 74 68 61 74 20 79 |ondition|s that y|
|00002480| 6f 75 20 61 72 65 6e 27 | 74 20 65 76 65 6e 0d 61 |ou aren'|t even.a|
|00002490| 77 61 72 65 20 6f 66 20 | 61 6e 64 20 74 68 75 73 |ware of |and thus|
|000024a0| 20 63 61 6e 6e 6f 74 20 | 65 78 70 6c 69 63 69 74 | cannot |explicit|
|000024b0| 6c 79 20 68 61 6e 64 6c | 65 20 61 6e 64 20 70 72 |ly handl|e and pr|
|000024c0| 65 76 65 6e 74 0d 74 68 | 65 6d 20 74 68 65 72 65 |event.th|em there|
|000024d0| 2e 0d 0d 48 6f 77 65 76 | 65 72 2c 20 77 68 61 74 |...Howev|er, what|
|000024e0| 20 79 6f 75 20 63 61 6e | 20 61 74 20 6c 65 61 73 | you can| at leas|
|000024f0| 74 20 64 6f 20 69 73 20 | 74 6f 20 74 61 6b 65 20 |t do is |to take |
|00002500| 63 61 72 65 0d 6f 66 20 | 74 68 6f 73 65 20 65 78 |care.of |those ex|
|00002510| 63 65 70 74 69 6f 6e 61 | 6c 20 63 61 73 65 73 20 |ceptiona|l cases |
|00002520| 61 6e 64 20 64 6f 20 61 | 20 22 63 6c 65 61 6e 75 |and do a| "cleanu|
|00002530| 70 22 20 6f 66 0d 74 68 | 65 20 64 61 74 61 20 79 |p" of.th|e data y|
|00002540| 6f 75 20 61 66 66 65 63 | 74 65 64 20 69 6e 20 74 |ou affec|ted in t|
|00002550| 68 61 74 20 73 75 62 72 | 6f 75 74 69 6e 65 2e 0d |hat subr|outine..|
|00002560| 0d 46 6f 72 20 69 6e 73 | 74 61 6e 63 65 2c 20 69 |.For ins|tance, i|
|00002570| 66 20 79 6f 75 20 6f 70 | 65 6e 20 61 6e 64 20 77 |f you op|en and w|
|00002580| 72 69 74 65 20 74 6f 20 | 61 20 66 69 6c 65 0d 69 |rite to |a file.i|
|00002590| 6e 20 61 20 73 75 62 72 | 6f 75 74 69 6e 65 2c 20 |n a subr|outine, |
|000025a0| 61 6e 64 20 74 68 65 6e | 20 73 6f 6d 65 20 75 6e |and then| some un|
|000025b0| 70 72 65 64 69 63 74 61 | 62 6c 65 20 65 72 72 6f |predicta|ble erro|
|000025c0| 72 2c 0d 6c 69 6b 65 20 | 61 20 73 74 61 63 6b 20 |r,.like |a stack |
|000025d0| 6f 76 65 72 66 6c 6f 77 | 2c 20 68 61 70 70 65 6e |overflow|, happen|
|000025e0| 73 20 69 6e 20 74 68 65 | 72 65 2c 0d 79 6f 75 20 |s in the|re,.you |
|000025f0| 73 68 6f 75 6c 64 20 61 | 74 20 6c 65 61 73 74 20 |should a|t least |
|00002600| 6d 61 6b 65 20 73 75 72 | 65 20 74 68 61 74 20 79 |make sur|e that y|
|00002610| 6f 75 20 63 6c 6f 73 65 | 20 74 68 65 0d 66 69 6c |ou close| the.fil|
|00002620| 65 20 62 65 66 6f 72 65 | 20 79 6f 75 20 6c 6f 73 |e before| you los|
|00002630| 65 20 69 74 73 20 72 65 | 66 65 72 65 6e 63 65 2e |e its re|ference.|
|00002640| 0d 0d 48 65 72 65 27 73 | 20 61 6e 20 65 78 61 6d |..Here's| an exam|
|00002650| 70 6c 65 3a 0d 0d 20 20 | 53 75 62 20 41 70 70 65 |ple:.. |Sub Appe|
|00002660| 6e 64 53 6f 6d 65 44 61 | 74 61 54 6f 46 69 6c 65 |ndSomeDa|taToFile|
|00002670| 20 28 66 69 6c 65 52 65 | 66 20 61 73 20 46 6f 6c | (fileRe|f as Fol|
|00002680| 64 65 72 49 74 65 6d 29 | 0d 20 20 20 20 44 69 6d |derItem)|. Dim|
|00002690| 20 66 69 6c 65 53 74 72 | 65 61 6d 20 41 73 20 54 | fileStr|eam As T|
|000026a0| 65 78 74 4f 75 74 70 75 | 74 53 74 72 65 61 6d 0d |extOutpu|tStream.|
|000026b0| 20 20 20 20 44 69 6d 20 | 6e 65 65 64 73 43 6c 6f | Dim |needsClo|
|000026c0| 73 65 20 61 73 20 42 6f | 6f 6c 65 61 6e 0d 20 20 |se as Bo|olean. |
|000026d0| 20 20 66 69 6c 65 53 74 | 72 65 61 6d 20 3d 20 66 | fileSt|ream = f|
|000026e0| 69 6c 65 52 65 66 2e 41 | 70 70 65 6e 64 54 6f 54 |ileRef.A|ppendToT|
|000026f0| 65 78 74 46 69 6c 65 0d | 20 20 20 20 6e 65 65 64 |extFile.| need|
|00002700| 73 43 6c 6f 73 65 20 3d | 20 74 72 75 65 0d 20 20 |sClose =| true. |
|00002710| 20 20 66 69 6c 65 53 74 | 72 65 61 6d 2e 57 72 69 | fileSt|ream.Wri|
|00002720| 74 65 4c 69 6e 65 20 28 | 22 6a 75 73 74 20 73 6f |teLine (|"just so|
|00002730| 6d 65 20 64 61 74 61 22 | 29 0d 20 20 20 20 6e 65 |me data"|). ne|
|00002740| 65 64 73 43 6c 6f 73 65 | 20 3d 20 66 61 6c 73 65 |edsClose| = false|
|00002750| 0d 20 20 20 20 66 69 6c | 65 53 74 72 65 61 6d 2e |. fil|eStream.|
|00002760| 43 6c 6f 73 65 0d 20 20 | 45 78 63 65 70 74 69 6f |Close. |Exceptio|
|00002770| 6e 20 65 78 63 20 61 73 | 20 52 75 6e 74 69 6d 65 |n exc as| Runtime|
|00002780| 45 78 63 65 70 74 69 6f | 6e 0d 20 20 20 20 27 20 |Exceptio|n. ' |
|00002790| 63 6c 65 61 6e 20 75 70 | 20 69 6e 20 63 61 73 65 |clean up| in case|
|000027a0| 20 6f 66 20 61 6e 79 20 | 65 72 72 6f 72 20 2d 20 | of any |error - |
|000027b0| 69 6e 20 74 68 69 73 20 | 63 61 73 65 2c 20 63 6c |in this |case, cl|
|000027c0| 6f 73 65 20 74 68 65 20 | 66 69 6c 65 20 69 66 20 |ose the |file if |
|000027d0| 69 74 20 69 73 20 73 74 | 69 6c 6c 20 6f 70 65 6e |it is st|ill open|
|000027e0| 0d 20 20 20 20 49 46 20 | 6e 65 65 64 73 43 6c 6f |. IF |needsClo|
|000027f0| 73 65 20 54 48 45 4e 0d | 20 20 20 20 20 20 66 69 |se THEN.| fi|
|00002800| 6c 65 53 74 72 65 61 6d | 2e 43 6c 6f 73 65 0d 20 |leStream|.Close. |
|00002810| 20 20 20 45 4e 44 0d 20 | 20 20 20 27 20 6e 6f 77 | END. | ' now|
|00002820| 20 70 61 73 73 20 6f 6e | 20 74 68 65 20 65 78 63 | pass on| the exc|
|00002830| 65 70 74 69 6f 6e 20 62 | 65 63 61 75 73 65 20 77 |eption b|ecause w|
|00002840| 65 27 72 65 20 6e 6f 74 | 20 61 62 6c 65 20 74 6f |e're not| able to|
|00002850| 20 68 61 6e 64 6c 65 20 | 69 74 20 68 65 72 65 0d | handle |it here.|
|00002860| 20 20 20 20 52 61 69 73 | 65 20 65 78 63 0d 20 20 | Rais|e exc. |
|00002870| 45 6e 64 20 53 75 62 0d | 0d 0d 4d 6f 72 65 20 69 |End Sub.|..More i|
|00002880| 64 65 61 73 20 66 6f 72 | 20 61 6e 20 65 66 66 65 |deas for| an effe|
|00002890| 63 74 69 76 65 20 65 78 | 63 65 70 74 69 6f 6e 20 |ctive ex|ception |
|000028a0| 68 61 6e 64 6c 69 6e 67 | 0d 2d 2d 2d 2d 2d 2d 2d |handling|.-------|
|000028b0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000028c0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000028d0| 2d 2d 2d 2d 2d 2d 2d 0d | 0d 54 68 65 73 65 20 77 |-------.|.These w|
|000028e0| 65 72 65 20 74 68 65 20 | 62 61 73 69 63 73 20 66 |ere the |basics f|
|000028f0| 6f 72 20 68 61 6e 64 6c | 69 6e 67 20 65 78 63 65 |or handl|ing exce|
|00002900| 70 74 69 6f 6e 73 20 69 | 6e 20 79 6f 75 72 20 63 |ptions i|n your c|
|00002910| 6f 64 65 2e 0d 0d 48 65 | 72 65 27 73 20 73 6f 6d |ode...He|re's som|
|00002920| 65 20 6d 6f 72 65 20 74 | 69 70 73 3a 0d 0d 2a 20 |e more t|ips:..* |
|00002930| 57 69 74 68 20 52 42 20 | 76 65 72 73 69 6f 6e 20 |With RB |version |
|00002940| 32 20 28 63 75 72 72 65 | 6e 74 6c 79 20 75 6e 64 |2 (curre|ntly und|
|00002950| 65 72 20 64 65 76 65 6c | 6f 70 6d 65 6e 74 29 20 |er devel|opment) |
|00002960| 79 6f 75 20 63 61 6e 0d | 20 20 70 61 73 73 20 61 |you can.| pass a|
|00002970| 72 67 75 6d 65 6e 74 73 | 20 74 6f 20 79 6f 75 72 |rguments| to your|
|00002980| 20 65 78 63 65 70 74 69 | 6f 6e 73 20 68 61 6e 64 | excepti|ons hand|
|00002990| 6c 65 72 73 20 6d 6f 72 | 65 20 65 61 73 69 6c 79 |lers mor|e easily|
|000029a0| 0d 20 20 62 79 20 75 73 | 69 6e 67 20 61 20 73 6f |. by us|ing a so|
|000029b0| 2d 63 61 6c 6c 65 64 20 | 63 6f 6e 73 74 72 75 63 |-called |construc|
|000029c0| 74 6f 72 3a 0d 20 20 49 | 6e 20 74 68 65 20 4d 79 |tor:. I|n the My|
|000029d0| 53 70 65 63 69 61 6c 45 | 78 63 65 70 74 69 6f 6e |SpecialE|xception|
|000029e0| 20 61 64 64 20 74 68 69 | 73 20 6d 65 74 68 6f 64 | add thi|s method|
|000029f0| 3a 0d 0d 20 20 20 20 53 | 75 62 20 4d 79 53 70 65 |:.. S|ub MySpe|
|00002a00| 63 69 61 6c 45 78 63 65 | 70 74 69 6f 6e 28 22 6d |cialExce|ption("m|
|00002a10| 73 67 20 61 73 20 53 74 | 72 69 6e 67 22 29 0d 20 |sg as St|ring"). |
|00002a20| 20 20 20 20 20 73 65 6c | 66 2e 6d 73 67 20 3d 20 | sel|f.msg = |
|00002a30| 6d 73 67 0d 20 20 20 20 | 45 6e 64 20 53 75 62 0d |msg. |End Sub.|
|00002a40| 0d 20 20 54 68 65 6e 20 | 79 6f 75 20 63 61 6e 20 |. Then |you can |
|00002a50| 72 61 69 73 65 20 65 78 | 63 65 70 74 69 6f 6e 73 |raise ex|ceptions|
|00002a60| 20 77 69 74 68 20 6d 65 | 73 73 61 67 65 73 20 65 | with me|ssages e|
|00002a70| 61 73 69 65 72 0d 20 20 | 75 73 69 6e 67 20 74 68 |asier. |using th|
|00002a80| 69 73 20 73 69 6e 67 6c | 65 20 6c 69 6e 65 3a 0d |is singl|e line:.|
|00002a90| 0d 20 20 20 20 52 61 69 | 73 65 20 6e 65 77 20 4d |. Rai|se new M|
|00002aa0| 79 53 70 65 63 69 61 6c | 45 78 63 65 70 74 69 6f |ySpecial|Exceptio|
|00002ab0| 6e 20 28 22 68 65 72 65 | 20 63 6f 6d 65 73 20 74 |n ("here| comes t|
|00002ac0| 68 65 20 6d 65 73 73 61 | 67 65 22 29 0d 0d 2a 20 |he messa|ge")..* |
|00002ad0| 41 6c 73 6f 20 61 76 61 | 69 6c 61 62 6c 65 20 69 |Also ava|ilable i|
|00002ae0| 6e 20 52 42 20 76 65 72 | 73 69 6f 6e 20 32 20 69 |n RB ver|sion 2 i|
|00002af0| 73 20 61 20 6e 65 77 20 | 75 6e 69 76 65 72 73 61 |s a new |universa|
|00002b00| 6c 20 74 79 70 65 2c 0d | 20 20 63 61 6c 6c 65 64 |l type,.| called|
|00002b10| 20 61 20 56 61 72 69 61 | 6e 74 2e 20 55 73 69 6e | a Varia|nt. Usin|
|00002b20| 67 20 74 68 61 74 2c 20 | 79 6f 75 20 63 61 6e 20 |g that, |you can |
|00002b30| 6d 61 6b 65 20 74 68 65 | 20 6d 65 73 73 61 67 69 |make the| messagi|
|00002b40| 6e 67 0d 20 20 6d 6f 72 | 65 20 76 65 72 73 61 74 |ng. mor|e versat|
|00002b50| 69 6c 65 20 62 79 20 63 | 68 61 6e 67 69 6e 67 20 |ile by c|hanging |
|00002b60| 69 74 73 20 74 79 70 65 | 20 66 72 6f 6d 20 53 74 |its type| from St|
|00002b70| 72 69 6e 67 20 74 6f 20 | 56 61 72 69 61 6e 74 2e |ring to |Variant.|
|00002b80| 0d 20 20 54 68 65 6e 20 | 79 6f 75 20 63 61 6e 20 |. Then |you can |
|00002b90| 70 61 73 73 20 61 6e 79 | 20 62 61 73 69 63 20 74 |pass any| basic t|
|00002ba0| 79 70 65 20 74 6f 20 69 | 74 2c 20 6c 69 6b 65 20 |ype to i|t, like |
|00002bb0| 53 74 72 69 6e 67 73 2c | 20 49 6e 74 65 67 65 72 |Strings,| Integer|
|00002bc0| 73 2c 0d 20 20 42 6f 6f | 6c 65 61 6e 73 20 65 74 |s,. Boo|leans et|
|00002bd0| 63 2e 0d 0d 54 68 61 74 | 27 73 20 69 74 20 66 6f |c...That|'s it fo|
|00002be0| 72 20 6e 6f 77 2e 20 50 | 6c 65 61 73 65 20 6c 65 |r now. P|lease le|
|00002bf0| 74 20 6d 65 20 6b 6e 6f | 77 20 69 66 20 79 6f 75 |t me kno|w if you|
|00002c00| 20 68 61 76 65 20 61 64 | 64 69 74 69 6f 6e 73 2c | have ad|ditions,|
|00002c10| 0d 63 6f 72 72 65 63 74 | 69 6f 6e 73 20 6f 72 20 |.correct|ions or |
|00002c20| 71 75 65 73 74 69 6f 6e | 73 20 74 6f 20 74 68 69 |question|s to thi|
|00002c30| 73 20 74 65 78 74 2e 20 | 57 72 69 74 65 20 74 6f |s text. |Write to|
|00002c40| 3a 20 72 62 40 74 65 6d | 70 65 6c 2e 6f 72 67 0d |: rb@tem|pel.org.|
|00002c50| 0d 57 72 69 74 74 65 6e | 20 61 6e 64 20 63 6f 70 |.Written| and cop|
|00002c60| 79 72 69 67 68 74 65 64 | 20 62 79 0d 20 20 54 68 |yrighted| by. Th|
|00002c70| 6f 6d 61 73 20 54 65 6d | 70 65 6c 6d 61 6e 6e 2c |omas Tem|pelmann,|
|00002c80| 20 4d 61 72 63 68 20 31 | 34 2c 20 39 39 0d 00 00 | March 1|4, 99...|
|00002c90| 00 16 00 01 00 00 00 00 | 00 0b 00 09 00 04 00 00 |........|........|
|00002ca0| 00 09 00 00 00 00 00 00 | 00 00 00 30 00 00 00 01 |........|...0....|
|00002cb0| 00 00 00 04 00 00 00 00 | 00 00 00 02 54 45 58 54 |........|....TEXT|
|00002cc0| 00 00 01 00 00 00 00 00 | 00 00 00 00 73 74 79 6c |........|....styl|
|00002cd0| 00 00 01 00 00 00 00 00 | 00 00 00 00 00 00 00 24 |........|.......$|
|00002ce0| 00 00 00 05 00 01 04 07 | 00 3c 00 53 02 9c 02 3c |........|.<.S...<|
|00002cf0| 00 00 00 00 00 00 01 70 | 8c 00 00 00 09 99 91 e0 |.......p|........|
|00002d00| 00 00 00 00 00 00 01 00 | 00 00 2c b2 00 00 2b b2 |........|..,...+.|
|00002d10| 00 00 00 6e 09 75 f7 00 | 33 6a 00 00 00 1c 00 6e |...n.u..|3j.....n|
|00002d20| 00 03 54 45 58 54 00 00 | 00 22 73 74 79 6c 00 00 |..TEXT..|."styl..|
|00002d30| 00 2e 64 72 61 67 00 00 | 00 3a 6b 77 73 74 00 00 |..drag..|.:kwst..|
|00002d40| 00 46 01 00 ff ff 00 00 | 00 00 00 00 00 00 01 00 |.F......|........|
|00002d50| ff ff 00 00 2b 3c 00 00 | 00 00 00 80 ff ff 00 00 |....+<..|........|
|00002d60| 2b 56 00 00 00 00 bf 4c | ff ff 00 00 2b 8a 00 e2 |+V.....L|....+...|
|00002d70| 67 18 | |g. | |
+--------+-------------------------+-------------------------+--------+--------+